import { cookies } from 'next/headers'
import ScrollContainer from './components/scroll-container'
import { fetcher } from '@/src/utils/fetcher'
import { getTranslations } from 'next-intl/server'

const Page: React.FC = async () => {
  const cookieStore = cookies()

  const [t, products] = await Promise.all([
    // 翻译
    getTranslations('home'),
    // 列表数据
    fetcher<Product[]>('/api/index/indexContent?type=cp', {
      cookieStore,
    }),
  ])

  return (
    <>
      <ScrollContainer
        products={products}
        m={{
          discoverMore: t('product.discoverMore'),
          exploreMore: t('product.exploreMore'),
        }}
        key={cookieStore?.get('NEXT_LOCALE')?.value || ''}
      />
    </>
  )
}

export default Page
